package com.software.chemistry.util;

import com.aspose.threed.ObjSaveOptions;
import com.aspose.threed.Scene;

import java.io.IOException;

/**
 * 格式转化工具
 */
public class FormatUtil {

    private static String PATH = "model/";

    /**
     * @param s : 十六进制文件
     * @return s : 转化为字符串
     */
    public static String hexStringToString(String s) {
        if (s == null || s.equals("")) {
            return null;
        }
        s = s.replace(" ", "");
        byte[] baKeyword = new byte[s.length() / 2];
        for (int i = 0; i < baKeyword.length; i++) {
            try {
                baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        try {
            s = new String(baKeyword, "UTF-8");
            new String();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return s;
    }

    public static void FbxToObj(String file, String id) {
        // 在 Scene 对象中加载 FBX
        Scene document = null;
        try {
            document = new Scene(PATH + "123.fbx");
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 创建 ObjSaveOptions 的实例
        ObjSaveOptions options = new ObjSaveOptions();
        // 将 FBX 保存为 OBJ
        try {
            String fileName = "model" + id + ".obj";
            document.save(fileName, options);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
